use Dosvid
go

if exists(select 1
		  from sysobjects
		  where name = 'CalendarEvents')
  drop table CalendarEvents
go

create table CalendarEvents
(
  Id int identity(1,1) not null,
  EventTypeId int not null,
  AssignedUserId int not null,
  EventText ntext not null,
  IsAutoCreated bit not null,
  CreatedDate datetime not null,
  CreatedUserId int not null,
  EventDate datetime not null,
  CalendarEventStatusId int not null,
  EventTime time not null
)  
go

alter table CalendarEvents add constraint PK_CalendarEvents_ID primary key(Id) 
go

alter table CalendarEvents add constraint FK_CalendarEvents_Users_AssignedUserId 
      foreign key (AssignedUserId) references Users(Id) on delete cascade
go

alter table CalendarEvents add constraint FK_CalendarEvents_Users_CreatedUserId 
      foreign key (CreatedUserId) references Users(Id)
go

alter table CalendarEvents add constraint FK_CalendarEvents_CalendarEventTypes_EventTypeId 
      foreign key (EventTypeId) references CalendarEventTypes(Id) on delete cascade
go

alter table CalendarEvents add constraint FK_CalendarEvents_CalendarEventStatuses_CalendarEventStatusId 
      foreign key (CalendarEventStatusId) references CalendarEventStatuses(Id) 
go


create nonclustered index IX_CalendarEvents_AssignedUserId on CalendarEvents
       (AssignedUserId asc)
go
